#INCLUDE "PROTHEUS.CH"
#INCLUDE "APWEBEX.CH"

User Function fswpva06
local		cHtml
local		NX		:= 1
Private	oObj	:= Nil

WEB EXTENDED INIT cHtml

If !Empty(HttpSession->aUser) .and. !Empty(HttpSession->aComan)

	If HttpPost->codigo == "fswpvagrava" .and. !Empty(HttpPost->codigo)
		oObj := WSFSWWSS01():New()
		oObj:oWSLISTAGRAVAR := FSWWSS01_STLISTAGRAVAR():New()
		oObj:oWSLISTAGRAVAR:oWSITENS := FSWWSS01_ARRAYOFSTGRAVAR():New()
		oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR := {}
		oObj:CGRAVACOMANDA := HttpSession->aComan[1]

		For NX:=1 To len(HttpSession->aLista)
			aAdd(oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR,FSWWSS01_STGRAVAR():New())
			oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR[NX]:nEZ2_QUANT := HttpSession->aLista[NX][1]
			oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR[NX]:cEZ2_PRODUTO := HttpSession->aLista[NX][2]
			oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR[NX]:nEZ2_VLUNIT := HttpSession->aLista[NX][3]
			oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR[NX]:cEZ2_ITEM := HttpSession->aLista[NX][4]
			oObj:oWSLISTAGRAVAR:oWSITENS:oWSSTGRAVAR[NX]:nEZ2_EXISTE := HttpSession->aLista[NX][5]

			If HttpSession->aLista[NX][5] == 0
				HttpSession->aLista[NX][5] := 4
			EndIf

			If HttpSession->aLista[NX][5] == 2
				HttpSession->aLista[NX][5] := 1
			EndIf
		
		Next NX
		If oObj:EGRAVACOMANDA()
			Return cHtml := oObj:CEGRAVACOMANDARESULT
		Else
			Return cHtml := GetWSCerror(3)
		EndIf
	Else
		Return cHtml := RedirPage( "u_fswpva03.apw" )
	EndIf
	
ElseIF !Empty(HttpSession->aUser) .and. Empty(HttpSession->aComan)
	Return cHtml := RedirPage( "u_fswpva02.apw" )
Else
	Return cHtml := RedirPage( "u_fswpva01.apw" )
EndIf

WEB EXTENDED END

Return cHtml